/*
 * @Author: lihaogn
 * @Date: 2021-12-18 20:55:52
 * @LastEditTime: 2021-12-27 21:54:46
 * @LastEditor: lihaogn
 * @Description: 权限模型迁移文件
 *   创建迁移文件：npx sequelize migration:generate --name=init-permissions
 *   运行迁移文件：npx sequelize db:migrate
 *   撤销迁移：npx sequelize-cli db:migrate:undo
 * @FilePath: \lix-admin-foundation-server\database\migrations\20211218125552-init-permissions.js
 */
"use strict";

module.exports = {
  up: async (queryInterface, Sequelize) => {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */

    const { DATE, STRING, TINYINT } = Sequelize;
    await queryInterface.createTable("permissions", {
      id: {
        type: STRING(40),
        primaryKey: true,
      },
      name: {
        type: STRING(20),
        allowNull: false,
        unique: "uk_permission_name",
      },
      mark: {
        type: STRING(30),
        allowNull: false,
        unique: "uk_permission_mark",
      },
      type: {
        // 权限类型：1-页面、2-操作
        type: TINYINT,
        allowNull: false,
      },
      description: {
        type: STRING(30),
      },
      parentId: {
        type: STRING(40),
        field: "parent_id",
      },
      createdAt: { type: DATE, field: "created_at" },
      updatedAt: { type: "TIMESTAMP", field: "updated_at" },
    });
  },

  down: async (queryInterface, Sequelize) => {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */

    await queryInterface.dropTable("permissions");
  },
};
